package com.gscitysfy.cus.drain.modules.command.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.command.dto.*;
import com.gscitysfy.cus.drain.modules.command.service.IDangerSituationManageService;
import com.gscitysfy.cus.drain.modules.command.service.IDrainDangerMsgPublishService;
import com.gscitysfy.cus.drain.modules.command.vo.DangerSituationManageQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2022-10-20 21:01:08
 */
@Tag(name = "指挥调度 -> 险情管理")
@AllArgsConstructor
@RestController
@RequestMapping("/danger")
public class DangerSituationManageController {

    private final IDangerSituationManageService iDangerSituationManageService;
    private final IDrainDangerMsgPublishService iDrainDangerMsgPublishService;
    @Operation(summary = "获取险情管理列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.COMMAND_DANGER_SOURCE, targetField = "source"),
            @FieldParam(dictType = DicConstant.COMMAND_DANGER_CATEGORY, targetField = "category")
    })
    @GetMapping("/list")
    public Result<IPage<DangerSituationManageDto>> pageList(IPageDto page, DangerSituationManageQuery query) {
        return Result.content(iDangerSituationManageService.fetchPage(page.getPage(), query));
    }

    @Operation(summary = "获取险情管理详情")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.COMMAND_DANGER_SOURCE, targetField = "source"),
            @FieldParam(dictType = DicConstant.COMMAND_DANGER_CATEGORY, targetField = "category")
    })
    @GetMapping("/{cmKid}")
    public Result<DangerSituationManageDto> fetchById(@PathVariable Long cmKid) {
        return Result.content(iDangerSituationManageService.fetchById(cmKid));
    }

    @Operation(summary = "获取险情管理详情")
    @GetMapping("/processing/{cmKid}")
    public Result<DangerSituationProcessingDto> processing(@PathVariable Long cmKid) {
        return Result.content(iDangerSituationManageService.processing(cmKid));
    }
    @Operation(summary = "获取监测报警详情")
    @GetMapping("/alarm/{cmKid}")
    public Result<DangerSituationProcessingDto> alarmDetail(@PathVariable Long cmKid) {
        return Result.content(iDangerSituationManageService.processing(cmKid));
    }

    @Operation(summary = "获取险情管理GIS看板")
    @GetMapping("/dashboard")
    public Result<Map<String, Long>> dashboard() {
        return Result.content(iDangerSituationManageService.dashboard());
    }

    @Operation(summary = "获取险情管理GIS列表")
    @GetMapping("/gis")
    public Result<List<DangerSituationManageDto>> gisList() {
        return Result.content(iDangerSituationManageService.fetchGis());
    }

    @Operation(summary = "获取险情管理统计列表")
    @GetMapping("/getXqTjList")
    public Result<List<StatisticalData>> getXqTjList(String dimon,String startDate,String endDate) {
        return Result.content(iDangerSituationManageService.getXqTjList( dimon, startDate, endDate));
    }
    @Operation(summary = "获取抢险出动统计列表")
    @GetMapping("/getQXCDList")
    public Result<List<StatisticalData>> getQXCDList(String dimon,String startDate,String endDate) {
        return Result.content(iDangerSituationManageService.getQXCDList( dimon, startDate, endDate));
    }


    @Operation(summary = "获取险情管理类型来源统计")
    @GetMapping("/getXqLXLYTjList")
    public Result<List<Map<String,Object>>> getXqLXLYTjList(String dimon) {
        return Result.content(iDangerSituationManageService.getXqLXLYTjList( dimon));
    }

    @Operation(summary = "获取抢险任务统计")
    @GetMapping("/getQXRWTimeList")
    public Result<List<Map<String,Object>>> getQXRWTimeList(String dimon,String startDate,String endDate) {
        return Result.content(iDangerSituationManageService.getXqLXLYTjList( dimon));
    }

    @Operation(summary = "新增险情管理")
    @PostMapping
    public Result<Boolean> save(@RequestBody DangerSituationManageDto dto) {
        return Result.content(iDangerSituationManageService.saveOrUpdate(dto));
    }

    @Operation(summary = "修改险情管理")
    @PutMapping
    public Result<Boolean> update(@RequestBody DangerSituationManageDto dto) {
        return Result.content(iDangerSituationManageService.saveOrUpdate(dto));
    }

    @Operation(summary = "删除险情管理")
    @PutMapping(value = "/delete")
    public Result<Boolean> delete(@RequestBody List<Long> idList) {
        return Result.content(iDangerSituationManageService.delete(idList));
    }

    @Operation(summary = "发布险情消息")
    @PostMapping(value = "/publishDangerMsg")
    public Result<Boolean> publishDangerMsg(@RequestBody DrainDangerMsgPublishDto dto) {
        return Result.content(iDrainDangerMsgPublishService.saveOrUpdate(dto));
    }
    @Operation(summary = "是否关闭")
    @PutMapping(value = "/close")
    public Result<Boolean> close(@RequestBody List<Long> idList) {
        return Result.content(iDangerSituationManageService.close(idList));
    }

    @Operation(summary = "启动预案")
    @PutMapping(value = "/launchPlan")
    public Result<Long> launchPlan(@RequestBody DangerSituationManageDto dto) {
        return Result.content(iDangerSituationManageService.launchPlan(dto));
    }


    @Operation(summary = "获取险情管理统计列表")
    @GetMapping("/getQxrwTjList")
    public Result<List<StatisticalData>> getQxrwTjList(String dimon,String startDate,String endDate) {
        return Result.content(iDangerSituationManageService.getQxrwTjList( dimon, startDate, endDate));
    }
}
